package ru.amse.tsyganov.jumleditor.view.activepoints;

import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;

import ru.amse.tsyganov.jumleditor.commands.Command;
import ru.amse.tsyganov.jumleditor.graphicaleditor.Coordinates;
import ru.amse.tsyganov.jumleditor.view.preferences.Colors;

public abstract class ActivePoint {
	
	private int temporaryActivePointX;
	
	private int temporaryActivePointY;
	
	private final int activePointWidth = 6;
	
	private final int activePointHeight = 6;
	
	public abstract int getCurrentActivePointX();
	
	public abstract int getCurrentActivePointY();
	
	public abstract Command createCommandForAction();
	
	public abstract void paintTempResult(GC gc, Coordinates coordinates);
	
	public void paintActivePoint(GC gc, Coordinates coordinates) {
		gc.setForeground(Colors.getBlackColor());
		gc.setBackground(Colors.getWhiteColor());
		Rectangle r = getRectangle();
		gc.fillRectangle(
				coordinates.fromModelXToScreenX(r.x),
				coordinates.fromModelYToScreenY(r.y),
				r.width, r.height);
		gc.drawRectangle(
				coordinates.fromModelXToScreenX(r.x),
				coordinates.fromModelYToScreenY(r.y),
				r.width, r.height);
	}

	public final Rectangle getRectangle() {
		return new Rectangle(
				getCurrentActivePointX() - getActivePointWidth() / 2, 
				getCurrentActivePointY() - getActivePointHeight() / 2, 
				getActivePointWidth(), getActivePointHeight());
	}
	
	public final Rectangle getAttractiveRectangle() {
		int margin = 5;
		return new Rectangle(
				getCurrentActivePointX() - getActivePointWidth() / 2 - margin, 
				getCurrentActivePointY() - getActivePointHeight() / 2 - margin, 
				getActivePointWidth() + 2 * margin, 
				getActivePointHeight() + 2 * margin);
	}
	
	public final void move(int x, int y) {
		temporaryActivePointX = x;
		temporaryActivePointY = y;
	}
	
	public abstract Cursor getCursor();
	
	public final int getActivePointHeight() {
		return activePointHeight;
	}
	
	public final int getActivePointWidth() {
		return activePointWidth;
	}
	
	public int getTemporaryActivePointX() {
		return temporaryActivePointX;
	}
	
	public int getTemporaryActivePointY() {
		return temporaryActivePointY;
	}
	
}
